package com.oocl.ajax.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.oocl.ajax.dao.AreaDao;
import com.oocl.ajax.factory.DBFactory;
import com.oocl.ajax.pojo.Area;


/**
 * @description: 
 * @author  XIEMI2
 * @date Aug 1, 2017 9:12:53 PM
 * @version 1.0
 */
public class AreaDaoImpl implements AreaDao{

	@Override
	public List<Area> queryByName(String name){
		List<Area> areas = new ArrayList<Area>();
		try {
			String sql = "select * from areas where area like '%'||?||'%'";

			Connection con = null;
			PreparedStatement pst = null;
			ResultSet rs = null;
				con = DBFactory.getCon();
				pst = con.prepareStatement(sql);
				pst.setString(1, name);
				rs = pst.executeQuery();
				while (rs.next()) {
					String id = rs.getString("id");
					String areaId = rs.getString("areaid");
					String area = rs.getString("area");
					String cityId = rs.getString("cityid");
					Area a = new Area(id, areaId, area, cityId);
					areas.add(a);
			}
			DBFactory.close(con, pst, rs);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return areas;
	}
}




